﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.Collections.ObjectModel;

namespace Sukul.SharePoint.Taxomatic.DTO
{
    [CollectionDataContract(ItemName="TermStore")]
    [Serializable]
    [XmlRoot("TermStores")]
    public class TermStores : Collection<TermStore>
    {}

    [DataContract]
    public class TermStore
    {
        [DataMember]
        [XmlAttribute("Id")]
        public Guid Id = default(Guid);

        [DataMember]
        [XmlAttribute("Name")]
        public string Name = string.Empty;

        [DataMember]
        [XmlAttribute("WorkingLanguage")]
        public int WorkingLanguage = 1033;

        [DataMember]
        [XmlArray("Languages")]
        [XmlArrayItem("Language")]
        public Collection<int> Languages = new Collection<int>();

        [DataMember]
        [XmlArray("TaxonomyGroups")]
        [XmlArrayItem("TaxonomyGroup")]
        public Collection<TaxonomyGroup> TaxonomyGroups = new Collection<TaxonomyGroup>();
    }

    [DataContract]
    [Serializable]
    public class TaxonomyGroup
    {
        [DataMember]
        [XmlAttribute("Id")]
        public Guid Id = default(Guid);

        [DataMember]
        [XmlAttribute("Name")]
        public string Name = string.Empty;

        [DataMember]
        [XmlAttribute("Description")]
        public string Description = string.Empty;

        [DataMember]
        [XmlAttribute("CreatedDate")]
        public DateTime CreatedDate = DateTime.Now;

        [DataMember]
        [XmlArray("Termsets")]
        [XmlArrayItem("Termset")]
        public Collection<Termset> Termsets = new Collection<Termset>();
    }

    [DataContract]
    [Serializable]
    public class Termset
    {
        [DataMember]
        [XmlAttribute("Id")]
        public Guid Id = default(Guid);

        [DataMember]
        [XmlAttribute("Name")]
        public string Name = string.Empty;

        [DataMember]
        [XmlAttribute("Description")]
        public string Description = string.Empty;

        [DataMember]
        [XmlAttribute("CreatedDate")]
        public DateTime CreatedDate = DateTime.Now;

        [DataMember]
        [XmlAttribute("LastModifiedDate")]
        public DateTime LastModifiedDate = DateTime.Now;

        [DataMember]
        [XmlArray("Terms")]
        [XmlArrayItem("Term")]
        public Collection<Term> Terms = new Collection<Term>();

        [DataMember]
        [XmlAttribute(AttributeName = "IsAvailableForTagging", DataType = "boolean")]
        public bool IsAvailableForTagging = false;

        [DataMember]
        [XmlAttribute(AttributeName = "IsOpenForTermCreation", DataType = "boolean")]
        public bool IsOpenForTermCreation = false;
    }

    [DataContract]
    [Serializable]
    public class Term
    {
        [DataMember]
        [XmlAttribute("Id")]
        public Guid Id = default(Guid);

        [DataMember]
        [XmlAttribute("Name")]
        public string Name = string.Empty;

        [DataMember]
        [XmlAttribute("Description")]
        public string Description = string.Empty;

        [DataMember]
        [XmlAttribute("Owner")]
        public string Owner = string.Empty;

        [DataMember]
        [XmlAttribute("LastModifiedDate")]
        public DateTime LastModifiedDate = DateTime.Now;

        [DataMember]
        [XmlArray("Terms")]
        [XmlArrayItem("Term")]
        public Collection<Term> Terms = new Collection<Term>();

        [DataMember]
        [XmlArray("Labels")]
        [XmlArrayItem("Label")]
        public Collection<Label> Labels = new Collection<Label>();

        [DataMember]
        [XmlAttribute("DefaultLabel")]
        public string DefaultLabel = string.Empty;

        [DataMember]
        [XmlIgnore]
        public Term SourceTerm = null;

        [DataMember]
        [XmlAttribute("IsAvailableForTagging")]
        public bool IsAvailableForTagging = false;

        [DataMember]
        [XmlAttribute("IsDeprecated")]
        public bool IsDeprecated = false;

        [DataMember]
        [XmlAttribute("IsKeyword")]
        public bool IsKeyword = false;
        
        [DataMember]
        [XmlAttribute("IsReused")]
        public bool IsReused = false;
        
        [DataMember]
        [XmlAttribute("IsRoot")]
        public bool IsRoot = false;

        [DataMember]
        [XmlAttribute("IsSourceTerm")]
        public bool IsSourceTerm = false;
        
    }

    [DataContract]
    [Serializable]
    public class Label
    {
        [DataMember]
        [XmlAttribute("IsDefaultForLanguage")]
        public bool IsDefaultForLanguage = false;

        [DataMember]
        [XmlAttribute("Language")]
        public int Language = 1033;

        [DataMember]
        [XmlAttribute("Value")]
        public string Value = string.Empty;
    }
}


